package com.last.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.last.entity.*;
import com.last.interceptor.gainUserId;
import com.last.mapper.OrderMapper;
import com.last.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;


@Service
@Transactional
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public PageResult<Order> listAllOrder(PageDTO<Order> pageDTO) {
        IPage<Order> iPage = new Page<>(pageDTO.getPage(),pageDTO.getLimit());
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        // 获取商户Id
        String userId = gainUserId.getUserInfo();
        if (StringUtils.isEmpty(userId)){
            PageResult<Order> result = new PageResult<>();
            result.setSuccess(false);
            result.setMsg("未登录");
            return result;
        }
        IPage<Order> page = orderMapper.listAllOrder(iPage, Integer.valueOf(userId));
        PageResult<Order> result = new PageResult<>();
        result.setData(page.getRecords());
        result.setPages(page.getPages());
        result.setTotal(page.getTotal());
        return result;
    }
}
